<template>
  <div class="header-box">
    <header class="header">
      <img @click="goAddress('index')" src="@/assets/images/logo.png" />
      <div class="title">{{ $route.meta.title }}</div>
      <div class="top-more">
        <i class="el-icon-more" @click="showListFun()" v-if="!showList"></i>
        <i class="el-icon-close" @click="hiddenList()" v-if="showList"></i>
      </div>
    </header>
    <div class="mask" v-if="showList">
      <ul>
        <li
          :class="'index' == $route.meta.title ? 'active' : ''"
          @click="goAddress('index')"
        >
          <p class="list-title">首页</p>
        </li>
        <li class="list-item list-item-news">
          <p
            class="list-title"
            @click="openList('news')"
            :class="'news' == $route.meta.title ? 'active' : ''"
          >
            新闻资讯<i v-if="newsIsOpen" class="arrow el-icon-arrow-up"></i
            ><i v-else class="arrow el-icon-arrow-down"></i>
          </p>
          <div class="top-list" v-if="newsIsOpen">
            <div
              class="top-list-item"
              v-for="item in newsCategory"
              :key="item.id"
            >
              <p @click="goNewsList(item)">{{ item.title }}</p>
            </div>
          </div>
        </li>
        <li class="list-item list-item-match">
          <p
            class="list-title"
            @click="openList('match')"
            :class="'about-match' == $route.meta.title ? 'active' : ''"
          >
            关于大会<i v-if="matchIsOpen" class="arrow el-icon-arrow-up"></i
            ><i v-else class="arrow el-icon-arrow-down"></i>
          </p>
          <div class="top-list" v-if="matchIsOpen">
            <div
              class="top-list-item"
              v-for="item in aboutMatchList"
              :key="item.id"
            >
              <p @click="goMatchDetails(item.id)">{{ item.title }}</p>
            </div>
            <div class="top-list-item">
              <p @click="goAddress('works')">获奖作品</p>
            </div>
          </div>
        </li>
        <li
          class="list-item"
          :class="'vote' == $route.meta.title ? 'active' : ''"
        >
          <p class="list-title">作品投票</p>
        </li>
        <li
          class="list-item"
          :class="'contact-us' == $route.meta.title ? 'active' : ''"
          @click="goAddress('contact-us')"
        >
          <p class="list-title">联系我们</p>
        </li>
        <li
          class="list-item"
          @click="goAddress('user-center')"
          :class="$route.name == 'wap-user-center' ? 'active' : ''"
          v-if="isLogin"
        >
          个人中心
        </li>
        <li class="login-box" v-else>
          <div
            class="login"
            :class="$route.name == 'wap-login' ? 'active' : ''"
            @click="goAddress('login')"
          >
            登录
          </div>
          |
          <div
            class="register"
            :class="$route.name == 'wap-register' ? 'active' : ''"
            @click="goAddress('register')"
          >
            注册
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions, mapMutations } from "vuex";
export default {
  data() {
    return {
      showList: false,
      matchIsOpen: false,
      newsIsOpen: false,
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.getNewsCategory();
      this.getAboutMatchList();
    },
    ...mapActions(["getNewsCategory", "getAboutMatchList"]),
    showListFun() {
      this.showList = true;
    },
    hiddenList() {
      this.showList = false;
    },
    goAddress(address) {
      this.hiddenList();
      this.newsIsOpen = false;
      this.matchIsOpen = false;
      this.$router.push({
        name: "wap-" + address,
      });
    },
    openList(type) {
      if (type == "news") {
        this.matchIsOpen = false;
        this.newsIsOpen = !this.newsIsOpen;
      } else {
        this.newsIsOpen = false;
        this.matchIsOpen = !this.matchIsOpen;
      }
    },
    goNewsList(item) {
      this.hiddenList();
      this.$router.push({
        name: "wap-news",
        query: {
          category_id: item.id,
          category_name: item.title,
        },
      });
    },
    goMatchDetails(id) {
      this.hiddenList();
      this.$router.push({
        name: "wap-about-match",
        query: { id: id },
      });
    },
  },
  computed: {
    ...mapGetters(["isLogin", "aboutMatchList", "newsCategory"]),
  },
};
</script>

<style scoped>
header {
  width: 100vw;
  height: 55px;
  background: #fff;
  display: flex;
  align-items: center;
  padding: 0 15px;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  box-shadow: 0px 2px 5px 0px rgba(189, 189, 189, 0.1);
}
header img {
  width: 100px;
  height: 30px;
}
header .title {
  flex: 1;
  font-size: 17px;
  color: #333;
  text-align: center;
}
header .top-more {
  width: 80px;
  height: 30px;
  text-align: right;
}
header .top-more i {
  font-size: 30px;
  color: #333;
}
.mask {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 99;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
}
.mask ul {
  position: absolute;
  top: 55px;
  left: 0;
  width: 100%;
  background: #fff;
}
.mask ul li {
  width: 100%;
  box-sizing: border-box;

  color: #333;
  line-height: 50px;
  text-align: center;
  font-size: 17px;
}
.mask ul li .list-title {
  margin: 0 40px;
  border-bottom: 1px solid #eee;
}
.mask ul li.active {
  background: rgba(0, 0, 0, 0.1);
  color: #0e93e4;
}
.top-list {
  background: #f5f5f5;
}
.login-box {
  display: flex;
}
.login-box div {
  flex: 1;
  text-align: left;
  margin: 0 5px;
}
.login-box .login {
  text-align: right;
}
.login-box .active {
  color: #0e93e4;
}
</style>